<template>
  <div class="tabs-menu">
    <el-breadcrumb >
      <el-breadcrumb-item v-for="(item, index) in breadcrumbList" :key="item.path">
          <div class="el-breadcrumb__inner is-link" @click="onBreadcrumbClick(item, index)">
            <!-- <el-icon v-show="item.meta.icon && globalStore.breadcrumbIcon" class="breadcrumb-icon">
              <component :is="item.meta.icon"></component>
            </el-icon> -->
            <span class="breadcrumb-title">{{ item.meta.title }}</span>
          </div>
        </el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from "vue-router";
import "./index.scss";
import { computed } from "vue";
import { useMenuStore } from "@/stores/modules/menu";
import { HOME_URL } from "@/config";
import { ElBreadcrumb, ElBreadcrumbItem } from "element-plus";
import { Menu } from "@/api/interface";
const route = useRoute();
const router = useRouter();
const menuStore = useMenuStore();
const breadcrumbList = computed(() => {
  let breadcrumbData =
    menuStore.breadcrumbListGet[route.matched[route.matched.length - 1].path] ??
    [];
  // 🙅‍♀️不需要首页面包屑可删除以下判断
  if (breadcrumbData[0].path !== HOME_URL) {
    breadcrumbData = [
      { path: HOME_URL, meta: { icon: "HomeFilled", title: "首页" } },
      ...breadcrumbData,
    ];
  }
  return breadcrumbData;
});

console.log("breadcrumbList", breadcrumbList.value);
const onBreadcrumbClick = (item: Menu.MenuOptions, index: number) => {
  if (index !== breadcrumbList.value.length - 1) router.push(item.path);
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
